package fds.framework.data;
import fds.framework.code.CODE_ERR;
import fds.framework.util.MakeCallerInfo;

public class DATA_ERR 
{
	private String   ErrMsg = "";
	private String   ErrCode = "";
	private Object[] ErrVal = null;
	private String   ErrPos = null;
	
	public DATA_ERR(String ErrCode, String ErrMsg)
	{
		this.init(ErrCode, ErrMsg);
	}
	
	public DATA_ERR(String ErrCode, String ErrMsg, Object ... args)
	{
		this.init(ErrCode, ErrMsg, args);
	}
	
	private void init(String ErrCode, String ErrMsg, Object ... args)
	{
		this.ErrMsg = ErrMsg;
		this.ErrCode = ErrCode;
		this.ErrVal = args;
		this.ErrPos = MakeCallerInfo.Make(1, this);
	}
	
	public String getErrCode()
	{
		return this.ErrCode;
	}
	
	public String getErrMsg()
	{
		return this.ErrMsg;
	}
	
	public CODE_ERR getCODE_ERR()
	{
		return CODE_ERR.getCODE_ERR_BY_CODE(this);
	}
	
	public CODE_ERR getCODE_ERR_REF()
	{
		return CODE_ERR.getCODE_ERR_BY_REF(this);
	}
	
	public String getBuildErrMsg()
	{
		StringBuilder sb = new StringBuilder();
		sb.append("ERROR CODE [");
		sb.append(this.ErrCode);
		sb.append("] ");
		if(ErrVal == null) 
		{
			sb.append(this.ErrMsg);
		}
		else
		{
			sb.append(String.format(this.ErrMsg, this.ErrVal));
		}
		if(true)
		{
			sb.append(" {");
			sb.append(this.ErrPos);
			sb.append("} ");
		}
		return sb.toString();
	}
}
